package com.nbsaas.boot.controller.lock;

import java.util.concurrent.ConcurrentHashMap;

public class DocumentService {
    private final ConcurrentHashMap<Integer, Boolean> lockMap = new ConcurrentHashMap<>();

    public void processDocument(int documentId) {
        if (lockMap.putIfAbsent(documentId, true) != null) {
            throw new IllegalStateException("该单据正在被其他人处理");
        }

        try {
            // 执行业务逻辑
            // ...
        } finally {
            // 处理完成后释放锁
            lockMap.remove(documentId);
        }
    }
}
